var userid, username, sqid;
var userTypeId=0;

$(document).ready(function () {

    $.ajax({
        url: '/commis/api/user/currentUser',
        type: "GET",
        async: false,
        dataType: 'json',
        data: {

        },
        success: function (response) {
            if (response.status==0) {
                var user =response.data;
                userTypeId=user.userTypeId;
                $('#glyname').html("欢迎您，" + response.data.realName+ "("+response.data.community.communityName+")");


                $.ajax({
                    url: '/commis/api/index/notify',
                    type: "GET",
                    async: false,
                    dataType: 'json',
                    success: function (result) {
                        if(result.status==0){
                            countNotify(result,true);
                        }


                    },error: function (msg) {
                        alert("发生错误");
                    }
                })


            } else if (response.status==1) {
                alert("登录用户已经过期，请重新登录");
                window.parent.location.href = "login.html";
            }
        },error: function (msg) {
            alert("登录用户已经过期，请重新登录");
            window.parent.location.href = "login.html";
        }
    })



    if (userTypeId != 1) {
        $("#adminSpan").remove();
    }

    if (userTypeId ==1) {
        $("#notify").remove();
    }

    if(userTypeId == 3||userTypeId == 6||userTypeId == 7||userTypeId == 8||userTypeId == 9){
        $("#wageDiv").remove();
    }

    if(userTypeId ==4){
        $("#wageSpan").remove();

    }else{
        $("#infoSpan").remove();
    }

});


//设置框架
$(function () {
    $("#Sellerber").frame({
        float: 'left',
        header: 70,//顶部高度
        bottom: 30,//底部高度
        menu: 200,//菜单栏宽度
        menu_nav: '.menu_list',
        color_btn: '.skin_select',
        Sellerber_menu: '.list_content',
        Sellerber_header: '.Sellerber_header',
    });
});
//时间设置
function currentTime() {
    var weekday = new Array(7)
    weekday[0] = "星期一"
    weekday[1] = "星期二"
    weekday[2] = "星期三"
    weekday[3] = "星期四"
    weekday[4] = "星期五"
    weekday[5] = "星期六"
    weekday[6] = "星期日"
    var d = new Date(), str = '';
    str += d.getFullYear() + '年';
    str += d.getMonth() + 1 + '月';
    str += d.getDate() + '日';
    str += d.getHours() + '时';
    str += d.getMinutes() + '分';
    str += d.getSeconds() + '秒' + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    str += weekday[d.getDay() - 1];
    return str;
}
setInterval(function () {
    $('#time').html(currentTime)
}, 1000);
$(".dropdown-content").on('mouseleave', function () {
    $(".dropdown-content").hide();
});
$("#notifyButton").on('click', function () {
    if($(".dropdown-content").is(":hidden")){
        $(".dropdown-content").show();    //如果元素为隐藏,则将它显现
        $("#notifyUl").children('li').remove();
        $.ajax({
            url: '/commis/api/index/notify',
            type: "GET",
            async: false,
            dataType: 'json',
            success: function (result) {
                if(result.status==0){


                    var count =countNotify(result,true);
                    if(count>0){//有记录才显示
                        $(".dropdown-content").show();
                        if (parseInt(result.data.allBackNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=0" class="fa  fa-bell" style="color: black" title="申请失败反馈记录">申请失败反馈记录<span style="color: red">'+ result.data.allBackNotify +'</span>条</a></li>');


                        }
                    }
                    if (userTypeId == 4){//社区通知

                        if(parseInt(result.data.attNotify)>0){
                            // $("#notifyUl").append('<li><a href="javascript:void(0)"  class="fa  fa-bell" style="color: black" >请添加当月考勤数据！</a></li>');
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="addAttendance.html?repeat=1" class="fa  fa-bell" style="color: black" title="添加当月考勤">请添加当月<span style="color: red">考勤</span>数据！</a></li>');


                        }
                        if(parseInt(result.data.overtimeNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="addOvertime.html?repeat=1" class="fa  fa-bell" style="color: black" title="添加当月加班表">请添加当月<span style="color: red">加班</span>数据！</a></li>');


                        }
                        if(parseInt(result.data.fundCommunityNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=7" class="fa  fa-bell" style="color: black" title="项目申报成功记录">项目申报成功记录<span style="color: red">'+ result.data.fundCommunityNotify +'</span>条</a></li>');

                        }
                        if(parseInt(result.data.officeCommunityNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=8" class="fa  fa-bell" style="color: black" title="办公经费申报成功记录">办公经费申报成功记录<span style="color: red">'+ result.data.officeCommunityNotify +'</span>条</a></li>');


                        }
                        if(parseInt(result.data.publicFundCommunityNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=9" class="fa  fa-bell" style="color: black" title="服务群众经费申报成功记录">服务群众经费申报成功记录<span style="color: red">'+ result.data.publicFundCommunityNotify +'</span>条</a></li>');


                        }
                        if(parseInt(result.data.constructionCommunityNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=10" class="fa  fa-bell" style="color: black" title="党务经费申报成功记录">党务经费申报成功记录<span style="color: red">'+ result.data.constructionCommunityNotify +'</span>条</a></li>');


                        }
                    }
                    else if (userTypeId == 2) { //资产通知
                        // var count = parseInt(result.data.addProNotify)+parseInt(result.data.delProNotify);
                        // $('#xxsl').html(count);

                        if(parseInt(result.data.addProNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=1" class="fa  fa-bell" style="color: black" title="添加资产记录">添加资产记录<span style="color: red">'+ result.data.addProNotify +'</span>条</a></li>');


                        }
                        if(parseInt(result.data.delProNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=2" class="fa  fa-bell" style="color: black" title="报废资产记录">报废资产记录<span style="color: red">'+ result.data.delProNotify +'</span>条</a></li>');


                        }
                        if(parseInt(result.data.attNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=13" class="fa  fa-bell" style="color: black" title="添加考勤记录">添加考勤记录<span style="color: red">'+ result.data.attNotify +'</span>条</a></li>');

                        }
                        if(parseInt(result.data.overtimeNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=14" class="fa  fa-bell" style="color: black" title="添加加班记录">添加加班记录<span style="color: red">'+ result.data.overtimeNotify +'</span>条</a></li>');

                        }
                    } else if (userTypeId == 3||userTypeId == 6||userTypeId == 7||userTypeId == 8||userTypeId == 9) {//申报公益金和经费 党务和群众经费通知

                        // var count = parseInt(result.data.fundNotify)
                        //     +parseInt(result.data.officeNotify)
                        //     +parseInt(result.data.publicFundNotify);
                        // $('#xxsl').html(count);

                        if(parseInt(result.data.fundNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=3" class="fa  fa-bell" style="color: black" title="申报公益金记录">申报公益金记录<span  style="color: red">'+ result.data.fundNotify +'</span>条</a></li>');


                        }
                        if(parseInt(result.data.officeNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=4" class="fa  fa-bell" style="color: black" title="申报办公经费记录">申报办公经费记录<span  style="color: red">'+ result.data.officeNotify +'</span>条</a></li>');


                        }
                        if(parseInt(result.data.publicFundNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=5" class="fa  fa-bell" style="color: black" title="申报服务群众经费记录">申报服务群众经费记录<span style="color: red">'+ result.data.publicFundNotify +'</span>条</a></li>');


                        }
                        if(parseInt(result.data.constructionNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=6" class="fa  fa-bell" style="color: black" title="申报党务经费记录">申报党务经费记录<span style="color: red">'+ result.data.constructionNotify +'</span>条</a></li>');


                        }
                    } if (userTypeId == 5) { //组织部通知
                        // var count = parseInt(result.data.publicFundNotify)
                        //     +parseInt(result.data.constructionNotify)
                        //     +parseInt(result.data.publicFundOrgNotify)
                        //     +parseInt(result.data.constructionOrgNotify)
                        // ;
                        // $('#xxsl').html(count);

                        if(parseInt(result.data.publicFundNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=5" class="fa  fa-bell" style="color: black" title="申报服务群众经费记录">申报服务群众经费记录<span style="color: red">'+ result.data.publicFundNotify +'</span>条</a></li>');


                        }
                        if(parseInt(result.data.constructionNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=6" class="fa  fa-bell" style="color: black" title="申报党务经费记录">申报党务经费记录<span style="color: red">'+ result.data.constructionNotify +'</span>条</a></li>');


                        }
                        if(parseInt(result.data.publicFundOrgNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=11" class="fa  fa-bell" style="color: black" title="服务群众经费申报成功记录">服务群众经费申报成功记录<span style="color: red">'+ result.data.publicFundOrgNotify +'</span>条</a></li>');


                        }
                        if(parseInt(result.data.constructionOrgNotify)>0){
                            $("#notifyUl").append('<li class="submenu"><a href="javascript:void(0)" name="notify.html?type=12" class="fa  fa-bell" style="color: black" title="党务经费申报成功记录">党务经费申报成功记录<span style="color: red">'+ result.data.constructionOrgNotify +'</span>条</a></li>');


                        }

                    }



                }


            },error: function (msg) {
                alert("发生错误");
            }
        })





    }else{
        $(".dropdown-content").hide();     //如果元素为显现,则将其隐藏
    }
    // $(".dropdown-content ").show();

});
$('#Exit_system').on('click', function () {
    layer.confirm('是否退出八里庄街道社区管理信息系统？', {
            btn: ['离开', '暂不'],//按钮
            icon: 2,
        },
        function () {
            location.href = "logout";
        });
});

$("#menu_style").niceScroll({
    cursorcolor: "#888888",
    cursoropacitymax: 1,
    touchbehavior: false,
    cursorwidth: "5px",
    cursorborder: "0",
    cursorborderradius: "5px"
});
/**
 * 获取URL的参数
 * @param name
 * @returns {*}
 */
function getUrlParam(name) {
    var url = location.search;
    var url = document.URL.toString();
    var tmpStr = name + "=";
    var tmp_reg = eval("/[\?&]" + tmpStr + "/i");
    if (url.search(tmp_reg) == -1) return null;
    else {
        var a = url.split(/[\?&]/);
        for (var i = 0; i < a.length; i++)
            if (a[i].search(eval("/^" + tmpStr + "/i")) != -1)return a[i].substring(tmpStr.length);
    }
}